package com.china08.yxyapi.service.yxyresource.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.china08.yxyapi.entity.es.ElasticYxyResResource;
import com.china08.yxyapi.service.yxyresource.YxyResourceService;
import com.china08.yxyapi.service.yxyresource.YxyResourceServicePointService;
import com.china08.yxyapi.util.YxUserPointsUtilV3;

@Service
public class YxyResourceServicePointServiceImpl implements YxyResourceServicePointService {

    @Autowired
    private YxyResourceService yrs;

    @Autowired
    private YxUserPointsUtilV3 yxUserPointsUtilV3;

    @Override
    public void audioPass(List<String> resourceIds) {
        List<ElasticYxyResResource> elasticYxyResResources = yrs.findByIds(resourceIds);
        for (ElasticYxyResResource elasticYxyResResource : elasticYxyResResources) {
            if (elasticYxyResResource.getViewScope() == 2) {
                if (StringUtils.equalsIgnoreCase(elasticYxyResResource.getTypeId(), "FMT04")) {
                    yxUserPointsUtilV3.uploadResourceVideo(elasticYxyResResource.getUploaderId());
                } else {
                    yxUserPointsUtilV3.uploadResourceTxt(elasticYxyResResource.getUploaderId());
                }
            }
        }
    }

    @Override
    public void downPublish(List<String> resourceIds) {
        List<ElasticYxyResResource> elasticYxyResResources = yrs.findByIds(resourceIds);
        for (ElasticYxyResResource elasticYxyResResource : elasticYxyResResources) {
            if (elasticYxyResResource.getViewScope() == 2) {
                if (StringUtils.equalsIgnoreCase(elasticYxyResResource.getTypeId(), "FMT04")) {
                    yxUserPointsUtilV3.downResourceVideo(elasticYxyResResource.getUploaderId());
                } else {
                    yxUserPointsUtilV3.downResourceTxt(elasticYxyResResource.getUploaderId());
                }
            }
        }
    }

}
